/*
 * types.h
 *
 *  Created on: Jan 14, 2014
 *      Author: ppks
 */

#ifndef TYPES_H_
#define TYPES_H_

#include "defines.h"

enum rc {
    ROLL,
    PITCH,
    YAW,
    THROTTLE,
    AUX1,
    AUX2,
    AUX3,
    AUX4,
    AUX5,
    AUX6,
    AUX7,
    AUX8
};

enum pid {
    PIDROLL,
    PIDPITCH,
    PIDYAW,
    PIDALT,
    PIDPOS,
    PIDPOSR,
    PIDNAVR,
    PIDLEVEL,
    PIDMAG,
    PIDVEL,     /* not used currently */
    PIDITEMS
};

/* List of the box items available in the current system configuration */
enum box {
    BOXARM,
#if ACC_INSTALLED
    BOXANGLE,
    BOXHORIZON,
#endif /* ACC_INSTALLED */
#if (BARO_INSTALLED) && (!defined(SUPPRESS_BARO_ALTHOLD))
    BOXBARO,
#endif /* BARO_INSTALLED */
#ifdef VARIOMETER
    BOXVARIO,
#endif /* VARIOMETER */
#if MAG_INSTALLED
    BOXMAG,
    BOXHEADFREE,
    BOXHEADADJ, // acquire heading for HEADFREE mode
#endif /* MAG_INSTALLED */
#if defined(SERVO_TILT) || defined(GIMBAL)  || defined(SERVO_MIX_TILT)
    BOXCAMSTAB,
#endif
#if defined(CAMTRIG)
    BOXCAMTRIG,
#endif /* defined(CAMTRIG) */
#if GPS_INSTALLED
    BOXGPSHOME,
    BOXGPSHOLD,
#endif /* GPS_INSTALLED */
#if defined(FIXEDWING) || defined(HELICOPTER)
    BOXPASSTHRU,
#endif /* defined(FIXEDWING) || defined(HELICOPTER) */
#if defined(BUZZER)
    BOXBEEPERON,
#endif /* defined(BUZZER) */
#if defined(LED_FLASHER)
    BOXLEDMAX,  /* we want maximum illumination */
    BOXLEDLOW,  /* low/no lights */
#endif /* defined(LED_FLASHER) */
#if defined(LANDING_LIGHTS_DDR)
    BOXLLIGHTS, /* enable landing lights at any altitude */
#endif /* defined(LANDING_LIGHTS_DDR) */
#ifdef INFLIGHT_ACC_CALIBRATION
    BOXCALIB,
#endif /* INFLIGHT_ACC_CALIBRATION */
#ifdef GOVERNOR_P
    BOXGOV,
#endif
#ifdef OSD_SWITCH
    BOXOSD,
#endif /* GOVERNOR_P */
#if GPS_NAVIGATION_ENABLED
    BOXGPSNAV,
    BOXLAND,
#endif /* GPS_NAVIGATION_ENABLED */
    CHECKBOXITEMS   /* Indicates the number of box items available in the system */
};

/* IMU data structure */
typedef struct {
    int16_t  accSmooth[3];
    int16_t  gyroData[3];
    int16_t  magADC[3];
    int16_t  gyroADC[3];
    int16_t  accADC[3];
} imu_t;

/* Calibration Structure */
typedef struct {
    uint8_t calibrationFlag;
    int16_t accBaseline[3];
    int16_t gyroBaseline[3];
    int16_t magBaseline[3];
    uint16_t checksum;
} calibration_data_t;

typedef struct {
    uint16_t AccCycles;
    uint16_t GyroCycles;
    uint16_t MagCycles;
    uint16_t BaroCycles;
} cal_t;

typedef struct {
    uint8_t  vbat;                  /* battery voltage in 0.1V steps */
    uint16_t intPowerMeterSum;
    uint16_t rssi;                  /* range: [0;1023] */
    uint16_t amperage;
} analog_t;

typedef struct {
    int32_t  estAltitude;           /* Estiamted Altitude in cm */
    int16_t  estSpeed;              /* variometer in cm/s */
} alt_t;

typedef struct {
    int16_t angle[2];               /* absolute angle inclination in multiple of 0.1 degree    180 deg = 1800 */
    int16_t heading;                /* variometer in cm/s */
} att_t;

/* Global Flags Structure that is accessible from any firmware module */
typedef struct {
    uint8_t OK_TO_ARM       :1 ;
    uint8_t ARMED           :1 ;
    uint8_t I2C_INIT_DONE   :1 ;    /* For i2c gps we have to now when i2c init is done, so we can update parameters to the i2cgps from eeprom (at startup it is done in setup()) */
    uint8_t ACCL_CALIBRATED :1 ;
    uint8_t NUNCHUKDATA     :1 ;
    uint8_t ANGLE_MODE      :1 ;
    uint8_t HORIZON_MODE    :1 ;
    uint8_t MAG_MODE        :1 ;
    uint8_t BARO_MODE       :1 ;
    uint8_t GPS_HOME_MODE   :1 ;
    uint8_t GPS_HOLD_MODE   :1 ;
    uint8_t HEADFREE_MODE   :1 ;
    uint8_t PASSTHRU_MODE   :1 ;
    uint8_t GPS_FIX         :1 ;
    uint8_t GPS_FIX_HOME    :1 ;
    uint8_t SMALL_ANGLES_25 :1 ;
    uint8_t CALIBRATE_MAG   :1 ;
    uint8_t VARIO_MODE      :1 ;
    uint8_t GPS_MODE        :2 ;    /* 0-3 NONE,HOLD, HOME, NAV (see GPS_MODE_* defines */
    uint8_t GPS_HEAD_SET    :1 ;    /* it is 1 if the navigation engine got commands to control heading (SET_POI or SET_HEAD) CLEAR_HEAD will zero it */
    uint8_t THROTTLE_IGNORED:1 ;    /* If it is 1 then ignore throttle stick movements in baro mode; */
    uint8_t GPS_BARO_MODE   :1 ;    /* This flag is used when GPS controls baro mode instead of user (it will replace rcOptions[BARO] */
    uint8_t LAND_COMPLETED  :1 ;
    uint8_t LAND_IN_PROGRESS:1 ;
} flags_struct_t;


#endif /* TYPES_H_ */
